package com.example.kotlin


fun test() {

}

class Runnoob {

}

class Practice1 {

}

fun sum(a: Int, b: Int): Int {
    return a + b
}

fun sum2(a: Int, b: Int) = a + b

public fun sum3(a: Int, b: Int): Int = a + b

private fun sum4(a: Int, b: Int) = a + b

fun printSum(a: Int, b: Int): Unit {
    println("sum of $a and $b is ${a + b}")
}

public fun printSum2(a: Int, b: Int) {
    println("sum of $a and $b is ${a + b}")
}

fun vars(vararg v: Int) {
    for (vt in v) {
        println("vt is $vt")
    }
}

fun main(args: Array<String>) {
    vars(1, 2, 3, 4, 5)

    println("---------------------------------------分割线-------------------------------------")

    val sumLambda: (Int, Int) -> Int = { x, y -> x + y }
    println(sumLambda(3, 4))

    println("---------------------------------------分割线-------------------------------------")

//    val a: Int = 1
//    val b = 1       // 系统自动推断变量类型为Int
//    val c: Int      // 如果不在声明时初始化则必须提供变量类型
//    c = 1           // 明确赋值
//
//    var x = 5        // 系统自动推断变量类型为Int
//    x += 1           // 变量可修改

    /**
     *
     * 这是注释
     *
     *
     *
     */

    var a = 1
    // 模板中的简单名称：
    val s1 = "a is $a"

    a = 2
    // 模板中的任意表达式：
    val s2 = "${s1.replace("is", "was")}, but now is $a"

    println(s1)
    println(s2)

    //类型后面加?表示可为空
    var age: String? = "23"
    //抛出空指针异常
    val ages = age!!.toInt()
    //不做处理返回 null
    val ages1 = age?.toInt()
    //age为空返回-1
    val ages2 = age?.toInt() ?: -1

    var i = age?.toInt() ?: -2

    var parseInt = Integer.parseInt(age)


}